package logic

import (
	"common/rabbitmq"
	"context"
	"log"
	order "order_server/proto"
)

// OrderCreate 订单创建(购物车结算)
func (o *OrderServer) OrderCreate(ctx context.Context, req *order.OrderCreateRequest) (*order.OrderCreateResponse, error) {
	log.Printf("开始处理订单创建请求，用户ID: %d", req.Uid)

	// 调用消息队列处理订单
	id, url := rabbitmq.SimPleRecieve()

	if id == 0 || url == "" {
		log.Printf("订单创建失败，用户ID: %d", req.Uid)
		return &order.OrderCreateResponse{
			OrderId: 0,
			Url:     "",
		}, nil
	}

	log.Printf("订单创建成功，订单ID: %d, 支付链接: %s", id, url)

	return &order.OrderCreateResponse{
		OrderId: id,
		Url:     url,
	}, nil
}
